package com.xjzd.spring.validated;

import jakarta.validation.constraints.Min;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@Slf4j
public class TestValidatedAnnotation {

    private final IService service;

    @PostMapping("/validated")
    public ResponseEntity<String> testValidatedAnnotation(@Validated @RequestBody User user) {
        System.out.println(user);
        return ResponseEntity.ok(service.sayHello(user));
    }

    @PostMapping("/validated2/{a}")
    public ResponseEntity<String> testValidatedAnnotation(@PathVariable @Min(2) int a, String name) {
        log.warn("{} {}", a, name);
        return ResponseEntity.ok(name);
    }
}
